"""
   -*- coding: utf-8 -*-
   @Time    : 2021/4/23 19:14
   @Author  : 狠欢
   @File    : 高阶函数.py
   @Software: PyCharm
"""
# 1.利用map批量检测用户名是否符合规范=> username符合规范,username不符合规范,·只能包含数字、字母、下划线，不以数字开头，长度在6-18之间
# import re
# def test(username):
#         res = re.findall(r'^[a-zA-Z_]\w{5,17}',username)
#         return res
# get_username = ['henhuratttttttttt1111WW','wqdsssssffffff','1212wdwq__wdqwd','__wdqdqwdEDEd323']
# s = map(test, get_username)
# for i in s:
#    if i == []:
#        print("不符合username规范")
#    else:
#        print("符合username规范")
#


# 2.filter把合法的用户名显示出来
# m = filter(test, get_username)
# for j in m:
#     print(j,"：符合username规范")

# 3.匿名函数+reduce实现1*2*3*...*n
# from  functools import reduce
#
# print(reduce(lambda x, y : x*y, [i for i in range(1, n)]))

# 4.filter函数:找出[1-100]能被3整除的数
# def f(n):
#     if n%3==0:
#         return n
# s = filter(f ,[i for i in range(1,10)])
# for i in s:
#     print(i)

# 5.map函数:求list[1-10]各项的平方
# s = map(lambda x:x**2,[i for i in range(1,11)])
# for i in s:
#     print(i)

# 6.将列表[1,4,5,9]转换成'1459'的字符串
# list1 = [1,4,5,9]
# from  functools import reduce
# print(reduce(lambda x,y:x*10+y,list1))
# print(''.join(map(str, list1)))
#

"""
7.有以下列表:list1=[7,-8，5,4,0，-2,-5]
a.正数在前负数在后
b.正数从小到大
c.负数从大到小
"""
list1 = [7, -8, 5, 4, 0, -2, -5]
s =sorted(list1,key=lambda x:-x)
s1 = sorted(s, key=lambda x:(-x)*100 if x<0 else x)
# print(s1)
# [0, 4, 5, 7, -2, -5, -8]
"""
8.这是一个字符串排序，排序规则:小写<大写<奇数<偶数. 
a. s = 'asdf234GDSdsf23'#排序:小写-大写-奇数-偶数·
b. 原理∶先比较元组的第一个值，FALSE
"""

s = 'asdf234GDSdsf23'

print("".join(sorted(s, key=lambda x: (x.isdigit(), x.isdigit() and int(x) % 2 == 0, x.isupper(), x))))



